package com.hxd.otc.module.convenience.model;

import android.support.annotation.NonNull;

import com.hxd.otc.api.IMarketApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.convenience.bean.AppStoreBean;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.uber.autodispose.AutoDisposeConverter;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by lzy on 2019/1/4 0004.
 * description ${应用市场model}
 */
public class MarketModel {
    private MarketModel() {
    }

    private static class SingletonHolder {
        private static final MarketModel instance = new MarketModel();
    }

    public static MarketModel getInstance() {
        return MarketModel.SingletonHolder.instance;
    }

    public void getMarketList(int currentPage, int showCount, @NonNull BaseObserver<BaseListBean<AppStoreBean>> observer,
                              AutoDisposeConverter<BaseBean<BaseListBean<AppStoreBean>>> converter) {
        getMarketApi().getMarketList(currentPage, showCount)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter).subscribe(observer);
    }

    public void countDownloadNums(String id, @NonNull BaseObserver<Object> observer,
                                  AutoDisposeConverter<BaseBean<Object>> converter) {
        getMarketApi().countDownloadNums(id)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter).subscribe(observer);
    }


    private IMarketApi getMarketApi() {
        return RetrofitManager.getDefault().create(IMarketApi.class);
    }
}
